Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
paypal-rest-api
Advanced tools
This package is NOT supported by PayPal. The current PayPal Node SDK does not support the newest Javascript features. This package is intended to support the most cutting edge Javascript features.
yarn add paypal-rest-api
All examples in this README are using Typescript, however this module can be included in CommonJS(require) as well. See the common.js example for how to use CommonJS with this module.
The most up to date configuration options can be found on the IConfigureOptions interface
import { PayPalRestApi } from "../src";
const paypal = new PayPalRestApi({
client_id: "", // Your paypal client id
client_secret": "", // Your paypal client secret
mode: "sandbox", // "production" or "sandbox"
requestOptions: {
maxRetries: 2, // Sets the number of retries for 500 or Network timeout. Set to 0 to disable.
retryDelay: 5000, // Microseconds to wait until next retry. 5000 = 5 seconds
// Any options from the following
// https://github.com/FGRibreau/node-request-retry
// https://github.com/request/request
},
});
It is STRONGLY recommended to use VSCode for the debugger and breakpoints. You must npm install first.
use the yarn run example script and pass in any file path from the examples folder.
git clone https://github.com/trainerbill/paypal-rest-api.git
cd paypal-rest-api
yarn install
yarn run example examples/invoice/model/create-update-send-get.ts
The repo provides some launch configurations and tasks for VsCode. Switch to the Debugger, open the example file you want to run, select the "Launch Example File" configuration and select run.
There are 3 different methods to make API Calls. It is STRONGLY recommended to use the Model approach. For full examples refer to the examples folder.
The modeling approach provides the most functionality. By storing the information in a model we can validate additional information before making another api call. For example, an invoice can only be deleted if it is in a DRAFT state. Using modeling we can prevent the delete api call unless the status is DRAFT. We also do not have to keep passing around ids since the information is stored on the model.
import { PayPalRestApi } from "paypal-rest-api";
const paypal = new PayPalRestApi({
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
mode: "sandbox",
});
const invoice = new paypal.invoice({
merchant_info: {
business_name: "testy",
},
});
// Create an invoice, send it, delete will throw an exception before sending the api call.
invoice.create()
.then(() => invoice.send())
.then(() => invoice.delete())
.catch((err) => console.log(err));
All api functions are available on the models. You can access them on the api property. Each API function takes the requestretry options as an argument so you set the body property to your api payload. Each API function returns a request response. All api functions are validated via a schema. Occasionally these may fail so please submit an issue.
import { PayPalRestApi } from "paypal-rest-api";
const paypal = new PayPalRestApi({
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
mode: "sandbox",
});
paypal.invoice.api.create({
body: {
merchant_info: {
business_name: "testy",
},
}
})
.then((response) => {
return response.body.id;
})
.then((id) => paypal.invoice.api.send(id))
.catch((err) => console.log(err));
If an API function does not exist or you are getting a false negative on a schema validation, you can always use the request method to directly execute an API call to an endpoint. You must specify the path, method, and more than likely the body.
import { PayPalRestApi } from "../src";
const paypal = new PayPalRestApi({
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
mode: "sandbox",
});
paypal.client.request({
body: {
merchant_info: {
business_name: "testy",
},
},
method: "POST",
uri: "v1/invoicing/invoices/",
})
.then((response) => console.log(response))
.catch((err) => console.error(err));
FAQs
A typescript module for integrating with PayPal REST APIs.
We found that paypal-rest-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.